/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import java.sql.*;
import java.util.logging.Logger;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JTable;

/**
 *
 * @author Daniel
 */
public class DatabaseHandler {
    private String dbUrl;       
    private String dbClass;     
    private String username;     
    private String password;
    private String name, company, country, attendant, idpassportnbr, knownorid, checkedby, viewName, viewCompany ; 
    
 
    public DatabaseHandler(String dbUrl, String username, String password){
        this.dbUrl = dbUrl;
        this.username = username;
        this.password = password;
        this.dbClass = "com.mysql.jdbc.Driver";
        }
        
    DateFormat dateFormat = new SimpleDateFormat("yyyy:MM:dd");
    Date date = new Date();
            
    public void setName(String inputName){
        name = inputName;
    }
    
    public String getName(){
        return name;
    }
    
    public String comparePassword(String user){
            try {
            
            Class.forName(dbClass);
            
            try (Connection con = DriverManager.getConnection(dbUrl, username, password)) {
                    Statement statement = con.createStatement();
                    ResultSet rs = statement.executeQuery("SELECT password FROM login_password WHERE username = " + user);
                    if(rs.next()){
                        return rs.getString("password");
                    }
                }
            } catch (ClassNotFoundException | SQLException e) {
               Logger.getLogger(this.getClass().getName(), e.getMessage());
            }
            return "";
    }    
}